﻿using Microsoft.AspNet.Identity.EntityFramework;
using MVCSecurity.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCSecurity.Controllers
{
    public class RoleController : Controller
    {
        ApplicationDbContext db = new ApplicationDbContext();

        //
        // GET: /Role/
        public ActionResult Index()
        {
            var model = new IdentityRole();
            ViewBag.Roles = db.Roles;
            return View(model);
        }

        public ActionResult Insert(IdentityRole model)
        {
            db.Roles.Add(model);
            db.SaveChanges();

            return RedirectToAction("Index");
        }

        public ActionResult Update(IdentityRole model)
        {
            db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            ViewBag.Roles = db.Roles;
            return View("Index", model);
        }

        public ActionResult Delete(String Id)
        {
            var role = db.Roles.Find(Id);
            db.Roles.Remove(role);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        public ActionResult Edit(String Id)
        {
            var role = db.Roles.Find(Id);
            ViewBag.Roles = db.Roles;
            return View("Index", role);
        }
	}
}